package com.jfinal.bbsapp.common.task;

import java.util.List;
import org.apache.log4j.Logger;

import com.jfinal.bbsapp.common.kit.MyAnnotation;
import com.jfinal.kit.PropKit;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;

@MyAnnotation(memo="订单收货确认处理业务类")
public class RecTaskService {
	
	private final Logger logger = Logger.getLogger(RecTaskService.class);
	private static final String DefaultRecDay = PropKit.get("DefaultRecDay");
	
	@MyAnnotation(memo="收货确认处理")
	public void dotask() {
		try {
			List<Record> list = Db.find("select orderid from b_shop_order where ispay='1' and flag='3'"
				+ " and posttime < (REPLACE(unix_timestamp(current_timestamp(3)),'.','') - ("+ Integer.valueOf(DefaultRecDay) +")*24*3600*1000)" );
			if(list.size() > 0){
				for(Record rec : list){
					if(rec != null) {
						Db.update("update b_shop_order set flag='4',rectime=? where orderid=?",System.currentTimeMillis(),rec.getStr("orderid"));
					}
				}
			}		
		} catch (Exception e) {
			logger.error("Exception:", e);
		}
		return;
	}
}
